// Learn cc.Class:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/class/index.html
// Learn Attribute:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/reference/attributes/index.html
// Learn life-cycle callbacks:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/life-cycle-callbacks/index.html
/**
 * pageview控件扩展
 */
cc.Class({
    extends: cc.PageView,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
    },

    getAngle:function(angx, angy) {
        return Math.atan2(angy, angx) * 180 / Math.PI;
    },

    _hasNestedViewGroup: function (event, captureListeners) {
        if(event.eventPhase !== cc.Event.CAPTURING_PHASE) return;   

        var touch = event.touch;
        if(!touch) 
        {

            return;
        }
        var deltaMove = cc.pSub(touch.getLocation(), touch.getStartLocation());
        var angy = Math.abs(deltaMove.y);
        var angx = Math.abs(deltaMove.x);
        var angle = this.getAngle(angx, angy);

        if ((angle >= 135 && angle <= 180) || (angle >= -180 && angle < -135) || angle >= -45 && angle <= 45){//左右 

            return false;
        } 

        if(captureListeners) {
            //captureListeners are arranged from child to parent
            for(var i = 0; i < captureListeners.length; ++i){
                var item = captureListeners[i];
                if(this.node === item) {
                    if(event.target.getComponent(cc.ViewGroup)) {
                        return true;
                    }

                    return false;
                }
                if(item.getComponent(cc.ViewGroup)) {
                    return true;
                }
            }
        }
    },
    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    // update (dt) {},
});
